const express = require("express")
const { v4 } = require("uuid")
const { query } = require("../db/db")
// const getIpAddress = require('../middleware/getIpAddress')
const router = express.Router()

router.get("/list", (req, res) => {
  const sql = `select * from blog_timeline order by point_time desc`
  const value = []
  query(sql, value).then(data=>{
    res.json(data)
  }).catch(err=>{
    res.json(err)
  })
})

router.post("/add", (req, res) => {
  console.log(req.body)
  const { point_time, title, content } = req.body
  const sql = `insert into blog_timeline set ?`
  const value = {
    id:v4().toString().replace(/-/g, ""),
    point_time,
    title,
    content,
    complexity:title?1:0
  }
  query(sql, value).then(data=>{
    res.json(data)
  }).catch(err=>{
    res.json(err)
  })
})

module.exports = router